class Solution {
    public int maximizeWin(int[] prizePositions, int k) {
        int n = prizePositions.length;
        int[] dp = new int[n + 1];
        int left = 0;
        int ans = 0;
        for (int right = 0; right < n; right++) {
            while (prizePositions[right] - prizePositions[left] > k) left++;
            ans = Math.max(ans, dp[left] + right - left + 1);
            dp[right + 1] = Math.max(dp[right], right - left + 1);
        }
        return ans;
    }
}